from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `user_tokens` (
    `id` CHAR(36) NOT NULL PRIMARY KEY,
    `token` VARCHAR(255) NOT NULL UNIQUE,
    `created_at` DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
    `expires_at` DATETIME(6) NOT NULL,
    `is_active` BOOL NOT NULL DEFAULT 1,
    `user_id` INT NOT NULL,
    CONSTRAINT `fk_user_tok_user_e908f61d` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP TABLE IF EXISTS `user_tokens`;"""
